//主文件
(function (w) {
    var inviteRd = function () {
        this.init();
        return this;
    }, c, userId = "", inviteCode = "", clickControl = true;

    inviteRd.prototype = {
        init: function () {
            c = this;
            /*  宝宝树66小区三期改造    mod  分享劫持处理 luolh  20171010   start   */
            // userId = getQueryString("userObjId");
            // inviteCode = getQueryString("inviteCode");


            var tmpUrls = window.location.href.split("index.html");
            if (tmpUrls.length > 1) {
                var tempUrlSearchs = tmpUrls[1].split("/");
                userId = tempUrlSearchs[1];

                var userObjId = tempUrlSearchs[1];
                inviteCode=tempUrlSearchs[2];
                var tempUserId=tempUrlSearchs[3];
                var feedsType=tempUrlSearchs[4];
                var uuid=tempUrlSearchs[5];
                var from=tempUrlSearchs[6];

                c.data = {
                    "url": (cw.serverUrl + "/rest/v1.0/mobile/web/getAppUserShare/" + userObjId
                    + "?userObjId="+userObjId
                    +"&inviteCode="+inviteCode
                    +"&userId="+tempUserId
                    +"&feedsType="+feedsType
                    +"&uuid="+uuid
                    +"&from="+from) ,
                    native: false
                };
                // c.data = {
                //     "url": cw.serverUrl + "/rest/v1.0/mobile/web/getAppUserShare/" + userId + location.search,
                //     native: false
                // };

                netWork(c.data, c.initData);
                $(".start-loading").css("display", "none");
            }
            /*  宝宝树66小区三期改造    mod  分享劫持处理 luolh  20171010   end   */
        },
        initData: function (data) {
            var pData = {communityId: data.data.communityId.objId};
            $(".avatar").prop("src", data.data.images);
            $("#nickName").text(data.data.nickName);
            c.data = {
                "url": cw.serverUrl + "/rest/v1.0/mobile/shares/getCommunityReward",
                native: false,
                method: "post",
                data: pData
            };
            netWork(c.data, function (data) {
                $("#score").text(data.data);

            });
        },
        phoneJudge: function (data) {
            if (data.result.status == 1) {
                $("#phone").text($("#text").val());
                $("#jifei-get-ok").css("display", "block");
                $('#wrapper').css("overflow", 'hidden');
            } else if (data.result.status == 2) {
                $('#tip').text('该手机号已被注册');
                $('#reged').css('display', 'block');
                $('#wrapper').css("overflow", 'hidden');
                setTimeout(function () {
                    document.getElementById('reged').style.display = 'none';
                    $('#wrapper').css("overflow", null);
                }, 2000);
            } else if (data.result.status == 3) {
                $("#jifei-geted").css("display", "block");
                $('#wrapper').css("overflow", 'hidden');
            }
            clickControl = true;
        },
        errorMethod: function () {
            clickControl = true;
        },
        evt: function () {
            $("#button").on("click", function (event) {
                if ($("#text").val() == "") {
                    clickControl = false;
                    $('#tip').text('请填写手机号码');
                    $('#reged').show();
                    $('#wrapper').css("overflow", 'hidden');
                    setTimeout(function () {
                        $('#reged').hide();
                        $('#wrapper').css("overflow", null);
                        clickControl = true;

                    }, 2000);
                } else if (!/^[1][3-9][0-9]{9,9}$/.test($("#text").val())) {

                    clickControl = false;
                    $('#tip').text('请填写正确的手机号码');
                    $('#reged').show();
                    $('#wrapper').css("overflow", 'hidden');
                    setTimeout(function () {
                        $('#reged').hide();
                        $('#wrapper').css("overflow", null);
                        clickControl = true;

                    }, 2000);

                }
                if (clickControl) {
                    clickControl = false;
                    var postData = {userId: userId, code: inviteCode, phone: $("#text").val()};
                    c.data = {
                        "url": cw.serverUrl + "/rest/v1.0/mobile/shares/addInvitationShare",
                        native: false,
                        method: "post",
                        data: postData,
                        prize: true,
                        error: c.errorMethod
                    };
                    netWork(c.data, c.phoneJudge);
                }

                event.preventDefault();
            });

            /*  宝宝树66小区三期改造    add  分享劫持处理 luolh  20171012   start   */
            // 您已成功接受邀请
            $("#invitationGo").on("click", function (event) {
                click_download();
                event.preventDefault();
            });
            // 马上去下载，跟邻居互动吧
            $("#inviteNeighbors").on("click", function (event) {
                click_download();
                event.preventDefault();
            });
            // 马上下载
            $("#inviteDownload").on("click", function (event) {
                click_download();
                event.preventDefault();
            });
            /*  宝宝树66小区三期改造    add  分享劫持处理 luolh  20171012   end   */
        }
    };

    w.inviteRd = inviteRd;
}(window));
var inviteReward = new inviteRd();
inviteReward.evt(inviteReward);

if (document.body.clientWidth <= 320) {
    $('.p1').css({'font-size': '1em'});

    $('#text, #button').css({'padding': '7px 0'});
    $('#text').css({'margin': '2% auto 3%'});
    $('#button').css({'padding': '9px 0'});
}

/*  宝宝树66小区二次改造    mod   luolh  20171001   start   */
function click_download() {
    var postData = {
        type: 65,
        typeDesc: '邀请有礼分享页面点击下载'
    };
    clickAcquisition(postData);
    toDownload();
}
var height = document.body.clientHeight;
//适配浏览器
if (document.body.clientWidth >= 640) {
    document.getElementsByClassName('noSelect')[0].className = 'noSelect';
    document.getElementsByTagName('html')[0].style.background = '#fff';
}

//表单
//    document.getElementById('text').onfocus = function () {
//        if (this.value == '请输入手机号码')this.value = '';
//    }

//    //隐藏 图层pop1
//    setTimeout(function () {
//        document.getElementById('reged').style.display = 'none';
//    }, 2000);
//隐藏 图层pop2
document.getElementById('jifei-geted-close').onclick = function () {
    document.getElementById('jifei-geted').style.display = 'none';
    $('#wrapper').css("overflow", null);
};
//隐藏 图层pop3
document.getElementById('jifei-getok-close').onclick = function () {
    document.getElementById('jifei-get-ok').style.display = 'none';
    $('#wrapper').css("overflow", null);
};
/*  宝宝树66小区二次改造    mod   luolh  20171001   end   */
